//
// Created by xili on 2024/8/8 18:19.
// Go big or go home.
//
#include <vector>
#include <numeric>

using namespace std;

class Solution {
public:
    int minOperations(vector<int> &nums) {
        int n = nums.size();
        int ans = 0;
        for (int i = 0; i < n - 2; i++) {
            if (nums[i] == 0) {
                ans++;
                nums[i] = 1 - nums[i];
                nums[i + 1] = 1 - nums[i + 1];
                nums[i + 2] = 1 - nums[i + 2];
            }
        }
        return accumulate(nums.begin(), nums.end(), 0) == n ? ans : -1;
    }
};